package com.osfw.framework.utils.bean;

import cn.hutool.core.util.NumberUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.osfw.framework.enums.DateStyle;
import com.osfw.framework.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import ma.glasnost.orika.CustomConverter;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.MappingContext;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import ma.glasnost.orika.metadata.Type;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.TemporalAccessor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * 对orika进行简单的封装
 */
@Slf4j
public class BeanMapper {
    private static MapperFactory mapperFactory;
    private static MapperFacade mapperFacade;


    static {
        mapperFactory = new DefaultMapperFactory.Builder().build();

        // 转 Byte 类型
        mapperFactory.getConverterFactory().registerConverter(new IntegerToByteConverter());
        mapperFactory.getConverterFactory().registerConverter(new LongToByteConverter());
        mapperFactory.getConverterFactory().registerConverter(new FloatToByteConverter());
        mapperFactory.getConverterFactory().registerConverter(new DoubleToByteConverter());
        mapperFactory.getConverterFactory().registerConverter(new BigDecimalToByteConverter());
        mapperFactory.getConverterFactory().registerConverter(new StringToByteConverter());
        mapperFactory.getConverterFactory().registerConverter(new CharacterToByteConverter());
        mapperFactory.getConverterFactory().registerConverter(new BooleanToByteConverter());
        mapperFactory.getConverterFactory().registerConverter(new ObjectToByteConverter());
        // 转 Integer 类型
        mapperFactory.getConverterFactory().registerConverter(new ByteToIntegerConverter());
        mapperFactory.getConverterFactory().registerConverter(new LongToIntegerConverter());
        mapperFactory.getConverterFactory().registerConverter(new FloatToIntegerConverter());
        mapperFactory.getConverterFactory().registerConverter(new DoubleToIntegerConverter());
        mapperFactory.getConverterFactory().registerConverter(new BigDecimalToIntegerConverter());
        mapperFactory.getConverterFactory().registerConverter(new StringToIntegerConverter());
        mapperFactory.getConverterFactory().registerConverter(new CharacterToIntegerConverter());
        mapperFactory.getConverterFactory().registerConverter(new BooleanToIntegerConverter());
        mapperFactory.getConverterFactory().registerConverter(new ObjectToIntegerConverter());
        // 转 Long 类型
        mapperFactory.getConverterFactory().registerConverter(new ByteToLongConverter());
        mapperFactory.getConverterFactory().registerConverter(new IntegerToLongConverter());
        mapperFactory.getConverterFactory().registerConverter(new FloatToLongConverter());
        mapperFactory.getConverterFactory().registerConverter(new DoubleToLongConverter());
        mapperFactory.getConverterFactory().registerConverter(new BigDecimalToLongConverter());
        mapperFactory.getConverterFactory().registerConverter(new DateToLongConverter());
        mapperFactory.getConverterFactory().registerConverter(new StringToLongConverter());
        mapperFactory.getConverterFactory().registerConverter(new CharacterToLongConverter());
        mapperFactory.getConverterFactory().registerConverter(new BooleanToLongConverter());
        mapperFactory.getConverterFactory().registerConverter(new ObjectToLongConverter());
        // 转 Float 类型
        mapperFactory.getConverterFactory().registerConverter(new ByteToFloatConverter());
        mapperFactory.getConverterFactory().registerConverter(new IntegerToFloatConverter());
        mapperFactory.getConverterFactory().registerConverter(new LongToFloatConverter());
        mapperFactory.getConverterFactory().registerConverter(new DoubleToFloatConverter());
        mapperFactory.getConverterFactory().registerConverter(new BigDecimalToFloatConverter());
        mapperFactory.getConverterFactory().registerConverter(new StringToFloatConverter());
        mapperFactory.getConverterFactory().registerConverter(new CharacterToFloatConverter());
        mapperFactory.getConverterFactory().registerConverter(new ObjectToFloatConverter());
        // 转 Double 类型
        mapperFactory.getConverterFactory().registerConverter(new ByteToDoubleConverter());
        mapperFactory.getConverterFactory().registerConverter(new IntegerToDoubleConverter());
        mapperFactory.getConverterFactory().registerConverter(new LongToDoubleConverter());
        mapperFactory.getConverterFactory().registerConverter(new FloatToDoubleConverter());
        mapperFactory.getConverterFactory().registerConverter(new BigDecimalToDoubleConverter());
        mapperFactory.getConverterFactory().registerConverter(new StringToDoubleConverter());
        mapperFactory.getConverterFactory().registerConverter(new CharacterToDoubleConverter());
        mapperFactory.getConverterFactory().registerConverter(new ObjectToDoubleConverter());
        // 转 BigDecimal 类型
        mapperFactory.getConverterFactory().registerConverter(new ByteToBigDecimalConverter());
        mapperFactory.getConverterFactory().registerConverter(new IntegerToBigDecimalConverter());
        mapperFactory.getConverterFactory().registerConverter(new LongToBigDecimalConverter());
        mapperFactory.getConverterFactory().registerConverter(new FloatToBigDecimalConverter());
        mapperFactory.getConverterFactory().registerConverter(new DoubleToBigDecimalConverter());
        mapperFactory.getConverterFactory().registerConverter(new StringToBigDecimalConverter());
        mapperFactory.getConverterFactory().registerConverter(new CharacterToBigDecimalConverter());
        mapperFactory.getConverterFactory().registerConverter(new ObjectToBigDecimalConverter());
        // 转 Character 类型
        mapperFactory.getConverterFactory().registerConverter(new StringToCharacterConverter());
        mapperFactory.getConverterFactory().registerConverter(new BooleanToCharacterConverter());
        mapperFactory.getConverterFactory().registerConverter(new ObjectToCharacterConverter());
        // 转 String 类型
        mapperFactory.getConverterFactory().registerConverter(new CharacterToStringConverter());
        mapperFactory.getConverterFactory().registerConverter(new ByteToStringConverter());
        mapperFactory.getConverterFactory().registerConverter(new IntegerToStringConverter());
        mapperFactory.getConverterFactory().registerConverter(new LongToStringConverter());
        mapperFactory.getConverterFactory().registerConverter(new FloatToStringConverter());
        mapperFactory.getConverterFactory().registerConverter(new DoubleToStringConverter());
        mapperFactory.getConverterFactory().registerConverter(new BigDecimalToStringConverter());
        mapperFactory.getConverterFactory().registerConverter(new DateToStringConverter());
        mapperFactory.getConverterFactory().registerConverter(new BooleanToStringConverter());
        mapperFactory.getConverterFactory().registerConverter(new ObjectToStringConverter());
        // 转 Date 类型
        mapperFactory.getConverterFactory().registerConverter(new LongToDateConverter());
        mapperFactory.getConverterFactory().registerConverter(new StringToDateConverter());
        mapperFactory.getConverterFactory().registerConverter(new ObjectToDateConverter());
        // 转 Boolbean 类型
        mapperFactory.getConverterFactory().registerConverter(new ByteToBooleanConverter());
        mapperFactory.getConverterFactory().registerConverter(new IntegerToBooleanConverter());
        mapperFactory.getConverterFactory().registerConverter(new LongToBooleanConverter());
        mapperFactory.getConverterFactory().registerConverter(new CharacterToBooleanConverter());
        mapperFactory.getConverterFactory().registerConverter(new StringToBooleanConverter());
        mapperFactory.getConverterFactory().registerConverter(new ObjectToBooleanConverter());
        mapperFacade = mapperFactory.getMapperFacade();

        // 利用SPI,注册Bean的转换规则（注释原因：由OrikaBeanPostprocessor代替进行转换规则注册）
        /*ServiceLoader<BeanMapperRegistry> serviceLoader = ServiceLoader.load(BeanMapperRegistry.class);
        for (BeanMapperRegistry beanMapperRegistry : serviceLoader) {
            beanMapperRegistry.registry(mapperFactory);
        }*/
    }

    public static <S, T> T map(S sourceObj, Class<T> targetClass) {
        return mapperFacade.map(sourceObj, targetClass);
    }

    public static <S, T> List<T> mapAsList(Iterable<S> sourceObj, Class<T> targetClass) {
        return mapperFacade.mapAsList(sourceObj, targetClass);
    }

    public static <S, T> IPage<T> mapAsPage(IPage<S> sourceObj, Class<T> targetClass) {
        List<T> dList = mapperFacade.mapAsList(sourceObj.getRecords(), targetClass);
        IPage<T> dPage = new Page();
        dPage.setTotal(sourceObj.getTotal());
        dPage.setRecords(dList);
        dPage.setSize(sourceObj.getSize());
        dPage.setCurrent(dPage.getCurrent());
        return dPage;
    }

    public static MapperFactory getMapperFactory() {
        return BeanMapper.mapperFactory;
    }


    public static <T> T setObjDefault(T sourceObj) {
        // 得到类对象
        Class objCla = sourceObj.getClass();
        Field[] fs = objCla.getDeclaredFields();
        for (int i = 0; i < fs.length; i++) {
            Field f = fs[i];

            // 设置些属性是可以访问的
            boolean isStatic = Modifier.isStatic(f.getModifiers());
            if (isStatic) {
                continue;
            }

            boolean isExclude = false;

            /*boolean isMapping = f.isAnnotationPresent(FieldMapping.class);
            if(isMapping){
                FieldMapping fieldMapping = f.getAnnotation(FieldMapping.class);
                if(fieldMapping.isSaveIgnore() != false ){
                    isExclude = fieldMapping.isSaveIgnore();
                }
            }*/

            if (isExclude) {
                continue;
            }

            // 设置些属性是可以访问的
            f.setAccessible(true);
            try {
                // 得到此属性的值
                Object val = f.get(sourceObj);
                // 得到此属性的类型
                String type = f.getType().toString();
                if (type.endsWith("String") && val == null) {
                    // 给属性设值
                    f.set(sourceObj, "");
                } else if ((type.endsWith("int") || type.endsWith("Integer") || type.endsWith("double")) && val == null) {
                    f.set(sourceObj, 0);
                } else if ((type.endsWith("long") || type.endsWith("Long")) && val == null) {
                    f.set(sourceObj, 0L);
                } else if (type.endsWith("Date") && val == null) {
                    f.set(sourceObj, java.sql.Date.valueOf("1970-01-01"));
                } else if (type.endsWith("Timestamp") && val == null) {
                    f.set(sourceObj, Timestamp.valueOf("1970-01-01 00:00:00"));
                } else if (type.endsWith("BigDecimal") && val == null) {
                    f.set(sourceObj, new BigDecimal(0));
                } else if ((type.endsWith("Boolean") || type.endsWith("boolean")) && val == null) {
                    f.set(sourceObj, false);
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return (T) sourceObj;
    }

    public static <T> Collection<T> setObjDefaultList(Iterable<T> objList) {
        Collection<T> list = new ArrayList();
        for (T t : objList) {
            list.add(setObjDefault(t));
        }
        return list;
    }

    /**************************************************自定义属性格式转换**************************************************/
    // 转 Byte 类型
    protected static class IntegerToByteConverter extends CustomConverter<Integer, Byte> {
        @Override
        public Byte convert(Integer source, Type<? extends Byte> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.byteValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class LongToByteConverter extends CustomConverter<Long, Byte> {
        @Override
        public Byte convert(Long source, Type<? extends Byte> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.byteValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class FloatToByteConverter extends CustomConverter<Float, Byte> {
        @Override
        public Byte convert(Float source, Type<? extends Byte> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.byteValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class DoubleToByteConverter extends CustomConverter<Double, Byte> {
        @Override
        public Byte convert(Double source, Type<? extends Byte> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.byteValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class BigDecimalToByteConverter extends CustomConverter<BigDecimal, Byte> {
        @Override
        public Byte convert(BigDecimal source, Type<? extends Byte> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.byteValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class StringToByteConverter extends CustomConverter<String, Byte> {
        @Override
        public Byte convert(String source, Type<? extends Byte> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return Byte.valueOf(source.trim());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class CharacterToByteConverter extends CustomConverter<Character, Byte> {
        @Override
        public Byte convert(Character source, Type<? extends Byte> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return Byte.valueOf(((Character) source).toString().trim());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class BooleanToByteConverter extends CustomConverter<Boolean, Byte> {
        @Override
        public Byte convert(Boolean source, Type<? extends Byte> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return Byte.valueOf(((Boolean) source) ? "1" : "0");
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class ObjectToByteConverter extends CustomConverter<Object, Byte> {
        @Override
        public Byte convert(Object source, Type<? extends Byte> destinationType, MappingContext context) {
            try {
                if (source instanceof Byte) {
                    return ((Byte) source).byteValue();
                } else if (source instanceof Integer) {
                    return ((Integer) source).byteValue();
                } else if (source instanceof Long) {
                    return ((Long) source).byteValue();
                } else if (source instanceof Float) {
                    return ((Float) source).byteValue();
                } else if (source instanceof Double) {
                    return ((Double) source).byteValue();
                } else if (source instanceof BigDecimal) {
                    return ((BigDecimal) source).byteValue();
                } else if (source instanceof String) {
                    return Byte.valueOf((String) ((String) source).trim());
                } else if (source instanceof Character) {
                    return Byte.valueOf(((Character) source).toString().trim());
                } else if (source instanceof Boolean) {
                    return Byte.valueOf(((Boolean) source) ? "1" : "0");
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    // 转 Integer 类型
    protected static class ByteToIntegerConverter extends CustomConverter<Byte, Integer> {
        @Override
        public Integer convert(Byte source, Type<? extends Integer> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.intValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class LongToIntegerConverter extends CustomConverter<Long, Integer> {
        @Override
        public Integer convert(Long source, Type<? extends Integer> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.intValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class FloatToIntegerConverter extends CustomConverter<Float, Integer> {
        @Override
        public Integer convert(Float source, Type<? extends Integer> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.intValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class DoubleToIntegerConverter extends CustomConverter<Double, Integer> {
        @Override
        public Integer convert(Double source, Type<? extends Integer> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.intValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class BigDecimalToIntegerConverter extends CustomConverter<BigDecimal, Integer> {
        @Override
        public Integer convert(BigDecimal source, Type<? extends Integer> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.intValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class StringToIntegerConverter extends CustomConverter<String, Integer> {
        @Override
        public Integer convert(String source, Type<? extends Integer> destinationType, MappingContext context) {
            try {
                if (source != null && NumberUtil.isNumber(source)) {
                    return Integer.valueOf(source.trim());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class CharacterToIntegerConverter extends CustomConverter<Character, Integer> {
        @Override
        public Integer convert(Character source, Type<? extends Integer> destinationType, MappingContext context) {
            try {
                if (source != null && NumberUtil.isNumber(source.toString())) {
                    return Integer.valueOf(source.toString().trim());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class BooleanToIntegerConverter extends CustomConverter<Boolean, Integer> {
        @Override
        public Integer convert(Boolean source, Type<? extends Integer> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return Integer.valueOf(source ? 1 : 0);
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class ObjectToIntegerConverter extends CustomConverter<Object, Integer> {
        @Override
        public Integer convert(Object source, Type<? extends Integer> destinationType, MappingContext context) {
            try {
                if (source instanceof Byte) {
                    return ((Byte) source).intValue();
                } else if (source instanceof Integer) {
                    return ((Integer) source).intValue();
                } else if (source instanceof Long) {
                    return ((Long) source).intValue();
                } else if (source instanceof Float) {
                    return ((Float) source).intValue();
                } else if (source instanceof Double) {
                    return ((Double) source).intValue();
                } else if (source instanceof BigDecimal) {
                    return ((BigDecimal) source).intValue();
                } else if (source instanceof String && NumberUtil.isNumber(source.toString())) {
                    return Integer.valueOf(((String) source).trim());
                } else if (source instanceof Character && NumberUtil.isNumber(source.toString())) {
                    return Integer.valueOf(((Character) source).toString().trim());
                } else if (source instanceof Boolean) {
                    return Integer.valueOf(((Boolean) source) ? 1 : 0);
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    // 转 Long 类型
    protected static class ByteToLongConverter extends CustomConverter<Byte, Long> {
        @Override
        public Long convert(Byte source, Type<? extends Long> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.longValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class IntegerToLongConverter extends CustomConverter<Integer, Long> {
        @Override
        public Long convert(Integer source, Type<? extends Long> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.longValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class FloatToLongConverter extends CustomConverter<Float, Long> {
        @Override
        public Long convert(Float source, Type<? extends Long> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.longValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class DoubleToLongConverter extends CustomConverter<Double, Long> {
        @Override
        public Long convert(Double source, Type<? extends Long> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.longValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class BigDecimalToLongConverter extends CustomConverter<BigDecimal, Long> {
        @Override
        public Long convert(BigDecimal source, Type<? extends Long> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.longValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class DateToLongConverter extends CustomConverter<Date, Long> {
        @Override
        public Long convert(Date source, Type<? extends Long> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.getTime();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class StringToLongConverter extends CustomConverter<String, Long> {
        @Override
        public Long convert(String source, Type<? extends Long> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    if (source instanceof String && dateStrIsValid(source, DateStyle.YYYYMMDD.getValue())) {
                        return DateUtils.stringToDate(source, DateStyle.YYYYMMDD).getTime();
                    } else if (source instanceof String && dateStrIsValid(source, DateStyle.YYYYMMDDHHMMSS.getValue())) {
                        return DateUtils.stringToDate(source, DateStyle.YYYYMMDDHHMMSS).getTime();
                    } else if (source instanceof String && dateStrIsValid(source, DateStyle.YYYY_MM_DD.getValue())) {
                        return DateUtils.stringToDate(source, DateStyle.YYYY_MM_DD).getTime();
                    } else if (source instanceof String && dateStrIsValid(source, DateStyle.YYYY_MM_DD_HH_MM.getValue())) {
                        return DateUtils.stringToDate(source, DateStyle.YYYY_MM_DD_HH_MM).getTime();
                    } else if (source instanceof String && dateStrIsValid(source, DateStyle.YYYY_MM_DD_HH_MM_SS.getValue())) {
                        return DateUtils.stringToDate(source, DateStyle.YYYY_MM_DD_HH_MM_SS).getTime();
                    } else if (source instanceof String && dateStrIsValid(source, DateStyle.YYYY_MM_DD_T_HH_MM_SS.getValue())) {
                        return DateUtils.stringToDate(source, DateStyle.YYYY_MM_DD_T_HH_MM_SS).getTime();
                    } else if (source instanceof String && source.contains("\\.") && dateStrIsValid(source.split("\\.")[0], DateStyle.YYYY_MM_DD_T_HH_MM_SS.getValue())) {
                        return DateUtils.stringToDate(source.split("\\.")[0], DateStyle.YYYY_MM_DD_T_HH_MM_SS).getTime();
                    } else if (source instanceof String && ("true".equalsIgnoreCase(source) || "false".equalsIgnoreCase(source))) {
                        return Long.valueOf("true".equalsIgnoreCase(source) ? 1 : 0);
                    } else if (source instanceof String && NumberUtil.isNumber(source)) {
                        return Long.valueOf((source).trim());
                    }
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class CharacterToLongConverter extends CustomConverter<Character, Long> {
        @Override
        public Long convert(Character source, Type<? extends Long> destinationType, MappingContext context) {
            try {
                if (source != null && NumberUtil.isNumber(source.toString())) {
                    return Long.valueOf(source.toString().trim());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class BooleanToLongConverter extends CustomConverter<Boolean, Long> {
        @Override
        public Long convert(Boolean source, Type<? extends Long> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return Long.valueOf(source ? 1 : 0);
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class ObjectToLongConverter extends CustomConverter<Object, Long> {
        @Override
        public Long convert(Object source, Type<? extends Long> destinationType, MappingContext context) {
            try {
                if (source instanceof Byte) {
                    return ((Byte) source).longValue();
                } else if (source instanceof Integer) {
                    return ((Integer) source).longValue();
                } else if (source instanceof Long) {
                    return ((Long) source).longValue();
                } else if (source instanceof Float) {
                    return ((Float) source).longValue();
                } else if (source instanceof Double) {
                    return ((Double) source).longValue();
                } else if (source instanceof BigDecimal) {
                    return ((BigDecimal) source).longValue();
                } else if (source instanceof Date) {
                    return ((Date) source).getTime();
                } else if (source instanceof String && dateStrIsValid((String) source, DateStyle.YYYYMMDD.getValue())) {
                    return DateUtils.stringToDate((String) source, DateStyle.YYYYMMDD).getTime();
                } else if (source instanceof String && dateStrIsValid((String) source, DateStyle.YYYYMMDDHHMMSS.getValue())) {
                    return DateUtils.stringToDate((String) source, DateStyle.YYYYMMDDHHMMSS).getTime();
                } else if (source instanceof String && dateStrIsValid((String) source, DateStyle.YYYY_MM_DD.getValue())) {
                    return DateUtils.stringToDate((String) source, DateStyle.YYYY_MM_DD).getTime();
                } else if (source instanceof String && dateStrIsValid((String) source, DateStyle.YYYY_MM_DD_HH_MM.getValue())) {
                    return DateUtils.stringToDate((String) source, DateStyle.YYYY_MM_DD_HH_MM).getTime();
                } else if (source instanceof String && dateStrIsValid((String) source, DateStyle.YYYY_MM_DD_HH_MM_SS.getValue())) {
                    return DateUtils.stringToDate((String) source, DateStyle.YYYY_MM_DD_HH_MM_SS).getTime();
                } else if (source instanceof String && dateStrIsValid((String) source, DateStyle.YYYY_MM_DD_T_HH_MM_SS.getValue())) {
                    return DateUtils.stringToDate((String) source, DateStyle.YYYY_MM_DD_T_HH_MM_SS).getTime();
                } else if (source instanceof String && NumberUtil.isNumber(source.toString())) {
                    return Long.valueOf(((String) source).trim());
                } else if (source instanceof Character && NumberUtil.isNumber(source.toString())) {
                    return Long.valueOf(((Character) source).toString().trim());
                } else if (source instanceof Boolean) {
                    return Long.valueOf(((Boolean) source) ? 1 : 0);
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    // 转 Float 类型
    protected static class ByteToFloatConverter extends CustomConverter<Byte, Float> {
        @Override
        public Float convert(Byte source, Type<? extends Float> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.floatValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class IntegerToFloatConverter extends CustomConverter<Integer, Float> {
        @Override
        public Float convert(Integer source, Type<? extends Float> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.floatValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class LongToFloatConverter extends CustomConverter<Long, Float> {
        @Override
        public Float convert(Long source, Type<? extends Float> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.floatValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class DoubleToFloatConverter extends CustomConverter<Double, Float> {
        @Override
        public Float convert(Double source, Type<? extends Float> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.floatValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class BigDecimalToFloatConverter extends CustomConverter<BigDecimal, Float> {
        @Override
        public Float convert(BigDecimal source, Type<? extends Float> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.floatValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class StringToFloatConverter extends CustomConverter<String, Float> {
        @Override
        public Float convert(String source, Type<? extends Float> destinationType, MappingContext context) {
            try {
                if (source != null && NumberUtil.isNumber(source.toString())) {
                    return Float.valueOf(source.trim());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class CharacterToFloatConverter extends CustomConverter<Character, Float> {
        @Override
        public Float convert(Character source, Type<? extends Float> destinationType, MappingContext context) {
            try {
                if (source != null && NumberUtil.isNumber(source.toString())) {
                    return Float.valueOf(source.toString().trim());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class ObjectToFloatConverter extends CustomConverter<Object, Float> {
        @Override
        public Float convert(Object source, Type<? extends Float> destinationType, MappingContext context) {
            try {
                if (source instanceof Byte) {
                    return ((Byte) source).floatValue();
                } else if (source instanceof Integer) {
                    return ((Integer) source).floatValue();
                } else if (source instanceof Long) {
                    return ((Long) source).floatValue();
                } else if (source instanceof Float) {
                    return ((Float) source).floatValue();
                } else if (source instanceof Double) {
                    return ((Double) source).floatValue();
                } else if (source instanceof BigDecimal) {
                    return ((BigDecimal) source).floatValue();
                } else if (source instanceof String && NumberUtil.isNumber(source.toString())) {
                    return Float.valueOf(((String) source).trim());
                } else if (source instanceof Character && NumberUtil.isNumber(source.toString())) {
                    return Float.valueOf(((Character) source).toString().trim());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    // 转 Double 类型
    protected static class ByteToDoubleConverter extends CustomConverter<Byte, Double> {
        @Override
        public Double convert(Byte source, Type<? extends Double> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.doubleValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class IntegerToDoubleConverter extends CustomConverter<Integer, Double> {
        @Override
        public Double convert(Integer source, Type<? extends Double> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.doubleValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class LongToDoubleConverter extends CustomConverter<Long, Double> {
        @Override
        public Double convert(Long source, Type<? extends Double> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.doubleValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class FloatToDoubleConverter extends CustomConverter<Float, Double> {
        @Override
        public Double convert(Float source, Type<? extends Double> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.doubleValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class BigDecimalToDoubleConverter extends CustomConverter<BigDecimal, Double> {
        @Override
        public Double convert(BigDecimal source, Type<? extends Double> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.doubleValue();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class StringToDoubleConverter extends CustomConverter<String, Double> {
        @Override
        public Double convert(String source, Type<? extends Double> destinationType, MappingContext context) {
            try {
                if (source != null && NumberUtil.isNumber(source.toString())) {
                    return Double.valueOf((source).trim());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class CharacterToDoubleConverter extends CustomConverter<Character, Double> {
        @Override
        public Double convert(Character source, Type<? extends Double> destinationType, MappingContext context) {
            try {
                if (source != null && NumberUtil.isNumber(source.toString())) {
                    return Double.valueOf((source).toString().trim());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class ObjectToDoubleConverter extends CustomConverter<Object, Double> {
        @Override
        public Double convert(Object source, Type<? extends Double> destinationType, MappingContext context) {
            try {
                if (source instanceof Byte) {
                    return ((Byte) source).doubleValue();
                } else if (source instanceof Integer) {
                    return ((Integer) source).doubleValue();
                } else if (source instanceof Long) {
                    return ((Long) source).doubleValue();
                } else if (source instanceof Float) {
                    return ((Float) source).doubleValue();
                } else if (source instanceof Double) {
                    return ((Double) source).doubleValue();
                } else if (source instanceof BigDecimal) {
                    return ((BigDecimal) source).doubleValue();
                } else if (source instanceof String && NumberUtil.isNumber(source.toString())) {
                    return Double.valueOf(((String) source).trim());
                } else if (source instanceof Character && NumberUtil.isNumber(source.toString())) {
                    return Double.valueOf(((Character) source).toString().trim());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    // 转 BigDecimal 类型
    protected static class ByteToBigDecimalConverter extends CustomConverter<Byte, BigDecimal> {
        @Override
        public BigDecimal convert(Byte source, Type<? extends BigDecimal> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return new BigDecimal(source.intValue());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class IntegerToBigDecimalConverter extends CustomConverter<Integer, BigDecimal> {
        @Override
        public BigDecimal convert(Integer source, Type<? extends BigDecimal> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return new BigDecimal(source.intValue());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class LongToBigDecimalConverter extends CustomConverter<Long, BigDecimal> {
        @Override
        public BigDecimal convert(Long source, Type<? extends BigDecimal> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return new BigDecimal(source.longValue());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class FloatToBigDecimalConverter extends CustomConverter<Float, BigDecimal> {
        @Override
        public BigDecimal convert(Float source, Type<? extends BigDecimal> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return new BigDecimal(source.floatValue());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class DoubleToBigDecimalConverter extends CustomConverter<Double, BigDecimal> {
        @Override
        public BigDecimal convert(Double source, Type<? extends BigDecimal> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return new BigDecimal(source.doubleValue());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class StringToBigDecimalConverter extends CustomConverter<String, BigDecimal> {
        @Override
        public BigDecimal convert(String source, Type<? extends BigDecimal> destinationType, MappingContext context) {
            try {
                if (source != null && NumberUtil.isNumber(source.toString())) {
                    return new BigDecimal(source.trim());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class CharacterToBigDecimalConverter extends CustomConverter<Character, BigDecimal> {
        @Override
        public BigDecimal convert(Character source, Type<? extends BigDecimal> destinationType, MappingContext context) {
            try {
                if (source != null && NumberUtil.isNumber(source.toString())) {
                    return new BigDecimal(source.toString().trim());
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class ObjectToBigDecimalConverter extends CustomConverter<Object, BigDecimal> {
        @Override
        public BigDecimal convert(Object source, Type<? extends BigDecimal> destinationType, MappingContext context) {
            try {
                if (source instanceof Byte) {
                    return new BigDecimal(((Byte) source).toString());
                } else if (source instanceof Integer) {
                    return new BigDecimal(source.toString());
                } else if (source instanceof Long) {
                    return new BigDecimal(source.toString());
                } else if (source instanceof Float) {
                    return new BigDecimal(source.toString());
                } else if (source instanceof Double) {
                    return new BigDecimal(source.toString());
                } else if (source instanceof String && NumberUtil.isNumber(source.toString())) {
                    return new BigDecimal((((String) source).trim()));
                } else if (source instanceof Character && NumberUtil.isNumber(source.toString())) {
                    return new BigDecimal(((Character) source).toString().trim());
                } else if (source instanceof BigDecimal) {
                    return ((BigDecimal) source);
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    // 转 Character 类型
    protected static class StringToCharacterConverter extends CustomConverter<String, Character> {
        @Override
        public Character convert(String source, Type<? extends Character> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return (source.trim()).charAt(0);
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class BooleanToCharacterConverter extends CustomConverter<Boolean, Character> {
        @Override
        public Character convert(Boolean source, Type<? extends Character> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return (source ? '1' : '0');
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class ObjectToCharacterConverter extends CustomConverter<Object, Character> {
        @Override
        public Character convert(Object source, Type<? extends Character> destinationType, MappingContext context) {
            try {
                if (source instanceof Character) {
                    return ((Character) source).charValue();
                } else if (source instanceof String) {
                    if (((String) source).length() > 0) {
                        return (((String) source).trim()).charAt(0);
                    }
                } else if (source instanceof Boolean) {
                    return (Boolean) source ? '1' : '0';
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    // 转 String 类型
    protected static class CharacterToStringConverter extends CustomConverter<Character, String> {
        @Override
        public String convert(Character source, Type<? extends String> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.toString();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class ByteToStringConverter extends CustomConverter<Byte, String> {
        @Override
        public String convert(Byte source, Type<? extends String> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.toString();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class IntegerToStringConverter extends CustomConverter<Integer, String> {
        @Override
        public String convert(Integer source, Type<? extends String> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.toString();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class LongToStringConverter extends CustomConverter<Long, String> {
        @Override
        public String convert(Long source, Type<? extends String> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.toString();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class FloatToStringConverter extends CustomConverter<Float, String> {
        @Override
        public String convert(Float source, Type<? extends String> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.toString();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class DoubleToStringConverter extends CustomConverter<Double, String> {
        @Override
        public String convert(Double source, Type<? extends String> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.toString();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class BigDecimalToStringConverter extends CustomConverter<BigDecimal, String> {
        @Override
        public String convert(BigDecimal source, Type<? extends String> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.toString();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class DateToStringConverter extends CustomConverter<Date, String> {
        @Override
        public String convert(Date source, Type<? extends String> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return DateUtils.dateToString(source, DateStyle.YYYY_MM_DD_HH_MM_SS);
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class BooleanToStringConverter extends CustomConverter<Boolean, String> {
        @Override
        public String convert(Boolean source, Type<? extends String> destinationType, MappingContext context) {
            try {
                if (source != null) {
                    return source.toString();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class ObjectToStringConverter extends CustomConverter<Object, String> {
        @Override
        public String convert(Object source, Type<? extends String> destinationType, MappingContext context) {
            try {
                if (source instanceof String) {
                    return ((String) source);
                } else if (source instanceof Character) {
                    return ((Character) source).toString();
                } else if (source instanceof Byte) {
                    return ((Byte) source).toString();
                } else if (source instanceof Integer) {
                    return ((Integer) source).toString();
                } else if (source instanceof Long) {
                    return ((Long) source).toString();
                } else if (source instanceof Float) {
                    return ((Float) source).toString();
                } else if (source instanceof Double) {
                    return ((Double) source).toString();
                } else if (source instanceof BigDecimal) {
                    return ((BigDecimal) source).toString();
                } else if (source instanceof Date) {
                    return DateUtils.dateToString((Date) source, DateStyle.YYYY_MM_DD_HH_MM_SS);
                } else if (source instanceof Boolean) {
                    return ((Boolean) source).toString();
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    // 转 Date 类型
    protected static class LongToDateConverter extends CustomConverter<Long, Date> {
        @Override
        public Date convert(Long source, Type<? extends Date> destinationType, MappingContext context) {
            try {
                if (source != null && source.longValue() != 0l) {
                    return new Date(source);
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class StringToDateConverter extends CustomConverter<String, Date> {
        @Override
        public Date convert(String source, Type<? extends Date> destinationType, MappingContext context) {
            try {
                if (dateStrIsValid(source, DateStyle.YYYYMMDD.getValue())) {
                    return DateUtils.stringToDate(source, DateStyle.YYYYMMDD);
                } else if (dateStrIsValid(source, DateStyle.YYYYMMDDHHMMSS.getValue())) {
                    return DateUtils.stringToDate(source, DateStyle.YYYYMMDDHHMMSS);
                } else if (dateStrIsValid(source, DateStyle.YYYY_MM_DD.getValue())) {
                    return DateUtils.stringToDate(source, DateStyle.YYYY_MM_DD);
                } else if (dateStrIsValid(source, DateStyle.YYYY_MM_DD_HH_MM.getValue())) {
                    return DateUtils.stringToDate(source, DateStyle.YYYY_MM_DD_HH_MM);
                } else if (dateStrIsValid(source, DateStyle.YYYY_MM_DD_HH_MM_SS.getValue())) {
                    return DateUtils.stringToDate(source, DateStyle.YYYY_MM_DD_HH_MM_SS);
                } else if (dateStrIsValid(source, DateStyle.YYYY_MM_DD_T_HH_MM_SS.getValue())) {
                    return DateUtils.stringToDate(source, DateStyle.YYYY_MM_DD_T_HH_MM_SS);
                } else if (source.contains("\\.") && dateStrIsValid(source.split("\\.")[0], DateStyle.YYYY_MM_DD_T_HH_MM_SS.getValue())) {
                    return DateUtils.stringToDate(source.split("\\.")[0], DateStyle.YYYY_MM_DD_T_HH_MM_SS);
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class ObjectToDateConverter extends CustomConverter<Object, Date> {
        @Override
        public Date convert(Object source, Type<? extends Date> destinationType, MappingContext context) {
            try {
                if (source instanceof Date) {
                    return ((Date) source);
                } else if (source instanceof String && dateStrIsValid((String) source, DateStyle.YYYYMMDD.getValue())) {
                    return DateUtils.stringToDate((String) source, DateStyle.YYYYMMDD);
                } else if (source instanceof String && dateStrIsValid((String) source, DateStyle.YYYYMMDDHHMMSS.getValue())) {
                    return DateUtils.stringToDate((String) source, DateStyle.YYYYMMDDHHMMSS);
                } else if (source instanceof String && dateStrIsValid((String) source, DateStyle.YYYY_MM_DD.getValue())) {
                    return DateUtils.stringToDate((String) source, DateStyle.YYYY_MM_DD);
                } else if (source instanceof String && dateStrIsValid((String) source, DateStyle.YYYY_MM_DD_HH_MM.getValue())) {
                    return DateUtils.stringToDate((String) source, DateStyle.YYYY_MM_DD_HH_MM);
                } else if (source instanceof String && dateStrIsValid((String) source, DateStyle.YYYY_MM_DD_HH_MM_SS.getValue())) {
                    return DateUtils.stringToDate((String) source, DateStyle.YYYY_MM_DD_HH_MM_SS);
                } else if (source instanceof String && dateStrIsValid((String) source, DateStyle.YYYY_MM_DD_T_HH_MM_SS.getValue())) {
                    return DateUtils.stringToDate((String) source, DateStyle.YYYY_MM_DD_T_HH_MM_SS);
                } else if (source instanceof String && source.toString().contains("\\.") && dateStrIsValid(source.toString().split("\\.")[0], DateStyle.YYYY_MM_DD_T_HH_MM_SS.getValue())) {
                    return DateUtils.stringToDate(source.toString().split("\\.")[0], DateStyle.YYYY_MM_DD_T_HH_MM_SS);
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    // 转Boolean
    protected static class StringToBooleanConverter extends CustomConverter<String, Boolean> {
        @Override
        public Boolean convert(String source, Type<? extends Boolean> destinationType, MappingContext context) {
            try {
                if ("ture".equalsIgnoreCase(source) || "false".equalsIgnoreCase(source)) {
                    return Boolean.valueOf(source);
                } else if ("0".equals(source) || "1".equals(source)) {
                    return "1".equals(source) ? true : false;
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class CharacterToBooleanConverter extends CustomConverter<Character, Boolean> {
        @Override
        public Boolean convert(Character source, Type<? extends Boolean> destinationType, MappingContext context) {
            try {
                if (source != null && ("1".equals(source) || "0".equals(source))) {
                    return "1".equals(String.valueOf(source)) ? true : false;
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class ByteToBooleanConverter extends CustomConverter<Byte, Boolean> {
        @Override
        public Boolean convert(Byte source, Type<? extends Boolean> destinationType, MappingContext context) {
            try {
                if (source == 0 || source == 1) {
                    return source == 1 ? true : false;
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class IntegerToBooleanConverter extends CustomConverter<Integer, Boolean> {
        @Override
        public Boolean convert(Integer source, Type<? extends Boolean> destinationType, MappingContext context) {
            try {
                if (source == 0 || source == 1) {
                    return source == 1 ? true : false;
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class LongToBooleanConverter extends CustomConverter<Long, Boolean> {
        @Override
        public Boolean convert(Long source, Type<? extends Boolean> destinationType, MappingContext context) {
            try {
                if (source == 0 || source == 1) {
                    return source == 1 ? true : false;
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    protected static class ObjectToBooleanConverter extends CustomConverter<Object, Boolean> {
        @Override
        public Boolean convert(Object source, Type<? extends Boolean> destinationType, MappingContext context) {
            try {
                if (source instanceof Boolean) {
                    return ((Boolean) source);
                } else if (source instanceof String && ("ture".equalsIgnoreCase((String) source) || "false".equalsIgnoreCase((String) source))) {
                    return Boolean.valueOf((String) source);
                } else if (source instanceof String && ("0".equals((String) source) || "1".equals((String) source))) {
                    return "1".equals((String) source) ? true : false;
                } else if (source instanceof Character && ("0".equals(String.valueOf(source)) || "1".equals(String.valueOf(source)))) {
                    return "1".equals(String.valueOf(source)) ? true : false;
                } else if (source instanceof Byte && ((Byte) source == 0 || (Byte) source == 1)) {
                    return (Byte) source == 1 ? true : false;
                } else if (source instanceof Integer && ((Integer) source == 0 || (Integer) source == 1)) {
                    return (Integer) source == 1 ? true : false;
                } else if (source instanceof Long && ((Long) source == 0 || (Long) source == 1)) {
                    return (Long) source == 1 ? true : false;
                }
            } catch (Exception e) {
                log.error("接入数据格式转换异常：", e);
            }
            return null;
        }
    }

    /**************************************************自定义属性格式转换**************************************************/


    /**
     * 验证字符串是否为指定日期格式
     *
     * @param rawDateStr 待验证字符串
     * @return 有效性结果, true 为正确, false 为错误
     */
    protected static boolean dateStrIsValid(String rawDateStr, String pattern) {

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
        TemporalAccessor date = null;
        try {
            date = dateTimeFormatter.parse(rawDateStr);
            return rawDateStr.equals(dateTimeFormatter.format(date));
        } catch (DateTimeParseException e) {
            return false;
        }
    }

}

